
var PayOrder_key = {

    //按键类型，0：首页 ，1 二次确认弹窗 ，2：支付密码弹窗 ，3：支付密码错误弹窗 4：重置密码弹窗 5：验证码认证订购弹窗 ，99 异常弹窗
    keyCode : "0",
    DEL_FROM_ID:"",
    //告警类型，0：支付密码告警 1：异常告警 2：订购成功告警 3：验证码告警 4：重置密码成功告警 5：重置密码告警 6：二次短信确认告警 7.订购验证码发送告警 8.订购验证码认证告警
    REPORT_TYPE : "0",

    //订购首页按键操作
    indexAction : function(key,btn_id){
        //返回键
        if(key == '8'){
            //用户行为轨迹
            var me = this;
            var UserID =  $("#user_id").val();
            var order_id = $("#order_id").val();
            var userBehaviors = PayOrder.USER_BEHAVIORS;
            if(userBehaviors == null || userBehaviors == 0){
                return false;
            }
            var params = {
                user_id : UserID,
                userBehaviors :userBehaviors ,
                log_source : "1",
                order_id : order_id,
            }
            Service.excute("ADD_USER_BEHAVIOR",false,params,function(reply){
                $(".focuse").removeClass("focuse");
                var back_url = $("#back_url").val();
                if(back_url != 'null' && back_url != '' && back_url != undefined){
                    window.location.href = back_url;
                    return false;
                }
                window.history.go(-1);
                PayOrder_window.showReportWindow("请按遥控器上的首页按钮！","1");
            });

        }
        //回车键
        if(key == '13'){
            var pay_mode =  $("#pay_mode").val() || "";
            if(pay_mode.indexOf("ZD_NATIVE") <= -1){
                return false;
            }
            //弹窗方式
            var isPopupWindow = $("#isPopupWindow").val();
            if("2" == isPopupWindow){
                //校验是否需要输入支付密码
                PayOrder_window.checkIsBhSetted();
            }else if("1" == isPopupWindow){
                //校验是否需要二次确认短信
                PayOrder.orderConfirmMsg();
            }else{
                //二次确认弹窗
                PayOrder_window.showSecConfirmWin();
            }
        }
        //操作其他按键不进行展示阴影
        if(key != '13' && key != '8'){
            //设置光标
            PayOrder.getFocusMethod();
        }
    },

    //二次确认按键操作
    manyAction : function(key,btn_id){
        //返回键
        if(key == '8'){
            PayOrder_window.hideSecConfirmWin();
            //设置光标
            PayOrder.getFocusMethod();
        }
        //回车键
        if(key == '13'){
            //支付完成、防止非法订购将订购完成方法做封装处理
            // if(btn_id=="button_btn"){
            //     PayOrder.createOrderZD("4");
            // 	PayOrder_window.hideSecConfirmWin();
            // }
            if(btn_id=="buttonCel_btn"){
                PayOrder_window.hideSecConfirmWin();
                //设置光标
                PayOrder.getFocusMethod();
            }
        }
        //左右点击事件
        if(key == '37' || key == '39' || key == '38' || key == '40'){
            if(btn_id == "button_btn"){
                $("#button_btn").removeClass("focuse");
                $("#buttonCel_btn").addClass("focuse");
            }
            if(btn_id == "buttonCel_btn"){
                $("#buttonCel_btn").removeClass("focuse");
                $("#button_btn").addClass("focuse");
            }
        }
    },
    //支付密码按键操作
    bhAction : function(key,btn_id){
        //返回键
        if(key == '8'){
            var password = $("#password").html();
            if((btn_id == 'password' && password!="")){
                var change_count = PayOrder.PASSWORD_COUNT;
                change_count = change_count.substring(0, change_count.length-1);
                PayOrder.PASSWORD_COUNT = change_count;
                var pwd = "";
                for(var i=0;i<PayOrder.PASSWORD_COUNT.length;i++){
                    pwd += "●";
                }
                $("#password").html(pwd);
                return false;
            }
            PayOrder_window.hideBhWindow();
            //设置光标
            PayOrder.getFocusMethod();
        }
        //回车键
        if(key == '13'){
            if(btn_id=="confirm_btn"){
                var passwordWord = PayOrder.PASSWORD_COUNT;
                if(passwordWord == null || passwordWord == " " || passwordWord == "" || passwordWord == undefined){
                    passwordWord=$("#password").val();
                }
                PayOrder_window.hideBhWindow();
                if(passwordWord == null || passwordWord == " " || passwordWord == "" || passwordWord == undefined){
                    PayOrder_window.showResetPwdSettedWindow("密码不能为空！");
                }else{
                    PayOrder.validateBhPsw(passwordWord);
                }
                $("#password").val("");
            }else if(btn_id=="cancel_btn"){
                PayOrder_window.hideBhWindow();
                PayOrder.getFocusMethod();
                $("#password").val("");
            }else if(btn_id =="password"){
                $("#password").removeClass("focuse");
                PayOrder_key.DEL_FROM_ID=btn_id;
                $("#keyboard").show();
                $("#num1").addClass("focuse");
            }else if(btn_id =="password_send_sms"){
                PayOrder_window.hideBhWindow();
                $("#password_send_sms").removeClass("focuse");
                PayOrder_window.showVsmsWindow();
            }else{
                var btn_value = $("#"+btn_id+"").attr('value');
                if(btn_value == "12"){//取消
                    $("#"+btn_id).removeClass("focuse");
                    //收起软键盘
                    PayOrder_window.keyboardWindow();
                    $("#password").addClass("focuse");
                }else if(btn_value == "10"){//清除
                    PayOrder.editPwdCode(PayOrder_key.DEL_FROM_ID);
                }else{
                    PayOrder.addPwdCode(btn_value,PayOrder_key.DEL_FROM_ID);
                }
            }
        }
        //左 右 点击事件
        if(event.keyCode == '37' || event.keyCode == '39' ){
            if(btn_id == "confirm_btn"){
                $("#confirm_btn").removeClass("focuse");
                $("#cancel_btn").addClass("focuse");
            }
            if(btn_id == "cancel_btn"){
                $("#cancel_btn").removeClass("focuse");
                $("#confirm_btn").addClass("focuse");
            }
            if(btn_id == "password"){
                $("#password").removeClass("focuse");
                $("#password_send_sms").addClass("focuse");
            }
            if(btn_id == "password_send_sms"){
                $("#password_send_sms").removeClass("focuse");
                $("#password").addClass("focuse");
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘左右按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //上点击事件
        if(event.keyCode == '38'){
            if(btn_id == "confirm_btn" || btn_id == "cancel_btn"){
                $("#cancel_btn").removeClass("focuse");
                $("#confirm_btn").removeClass("focuse");
                $("#password").addClass("focuse");
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘左右按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //下点击事件
        if(event.keyCode == '40'){
            if(btn_id == "password" || btn_id == "password_send_sms"){
                $("#password").removeClass("focuse");
                $("#password_send_sms").removeClass("focuse");
                $("#confirm_btn").addClass("focuse");
            }
            if(btn_id == "confirm_btn" || btn_id == "cancel_btn"){
                if(PayOrder_key.DEL_FROM_ID!=""){
                    $("#cancel_btn").removeClass("focuse");
                    $("#confirm_btn").removeClass("focuse");
                    $("#num1").addClass("focuse");
                }
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘左右按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //输入框
        if(btn_id == "password") {
            var count = getReomteCount(event.keyCode);
            if(count != "" && PayOrder.PASSWORD_COUNT.length<6) {
                PayOrder.PASSWORD_COUNT = PayOrder.PASSWORD_COUNT + count;
                var pwd = "";
                for(var i=0;i<PayOrder.PASSWORD_COUNT.length;i++){
                    pwd += "●";
                }
                $("#password").html(pwd);
            }
        }
    },
    //支付短信验证码订购按键操作
    bh_sms_Action : function(key,btn_id){
        //返回键
        if(key == '8'){
            var v_sms_Text = $("#v_sms_Text").html();
            if((btn_id == 'v_sms_Text' && v_sms_Text!="")){
                v_sms_Text = v_sms_Text.substring(0, v_sms_Text.length-1);
                $("#v_sms_Text").html(v_sms_Text);
                return false;
            }
            PayOrder_window.hideVsmsWindow();
            //设置光标
            PayOrder.getFocusMethod();
        }
        //回车键
        if(key == '13'){
            if(btn_id=="v_sms_confirm_btn"){
                PayOrder_window.hideVsmsWindow();
                PayOrder.resetVbhsms();
            }else if(btn_id=="v_sms_cancel_btn"){
                PayOrder_window.hideVsmsWindow();
                PayOrder.getFocusMethod();
            }else if(btn_id =="v_sms_Text"){
                $("#v_sms_Text").removeClass("focuse");
                PayOrder_key.DEL_FROM_ID=btn_id;
                $("#keyboard").show();
                $("#num1").addClass("focuse");
            }else if(btn_id =="sendSmsBhBtn"){
                if(PayOrder.READ_SECOND == "1") {
                    return false;
                }else {
                    PayOrder_window.hideVsmsWindow();
                    $("#sendSmsBhBtn").removeClass("focuse");
                    PayOrder.sendRandomSmsForReset(btn_id);
                    PayOrder.setDisabledTime(btn_id,60);
                }
            }else{
                var btn_value = $("#"+btn_id+"").attr('value');
                if(btn_value == "12"){//取消
                    $("#"+btn_id).removeClass("focuse");
                    //收起软键盘
                    PayOrder_window.keyboardWindow();
                    $("#v_sms_Text").addClass("focuse");
                }else if(btn_value == "10"){//清除
                    PayOrder.editPwdCode(PayOrder_key.DEL_FROM_ID);
                }else{
                    PayOrder.addPwdCode(btn_value,PayOrder_key.DEL_FROM_ID);
                }
            }
        }
        //左 右 点击事件
        if(event.keyCode == '37' || event.keyCode == '39' ){
            if(btn_id == "v_sms_confirm_btn"){
                $("#v_sms_confirm_btn").removeClass("focuse");
                $("#v_sms_cancel_btn").addClass("focuse");
            }
            if(btn_id == "v_sms_cancel_btn"){
                $("#v_sms_cancel_btn").removeClass("focuse");
                $("#v_sms_confirm_btn").addClass("focuse");
            }
            if(btn_id == "v_sms_Text"){
                $("#v_sms_Text").removeClass("focuse");
                $("#sendSmsBhBtn").addClass("focuse");
            }
            if(btn_id == "sendSmsBhBtn"){
                $("#sendSmsBhBtn").removeClass("focuse");
                $("#v_sms_Text").addClass("focuse");
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //上点击事件
        if(event.keyCode == '38'){
            if(btn_id == "v_sms_confirm_btn" || btn_id == "v_sms_cancel_btn"){
                $("#v_sms_confirm_btn").removeClass("focuse");
                $("#v_sms_cancel_btn").removeClass("focuse");
                $("#v_sms_Text").addClass("focuse");
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //下点击事件
        if(event.keyCode == '40'){
            if(btn_id == "v_sms_Text" || btn_id == "sendSmsBhBtn"){
                $("#v_sms_Text").removeClass("focuse");
                $("#sendSmsBhBtn").removeClass("focuse");
                $("#v_sms_confirm_btn").addClass("focuse");
            }
            if(btn_id == "v_sms_confirm_btn" || btn_id == "v_sms_cancel_btn"){
                if(PayOrder_key.DEL_FROM_ID!=""){
                    $("#v_sms_confirm_btn").removeClass("focuse");
                    $("#v_sms_cancel_btn").removeClass("focuse");
                    $("#vsms1").addClass("focuse");
                };
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //验证码输入框
        if(btn_id == "v_sms_Text") {
            var count = getReomteCount(event.keyCode);
            var v_sms_Text = $("#v_sms_Text").html();
            if(count != "" && v_sms_Text.length<6) {
                v_sms_Text = v_sms_Text + count;
                $("#v_sms_Text").html(v_sms_Text);
            }
        }
    },
    //系统异常按键操作
    errorAction : function(key,btn_id){
        //返回键
        if(key == '8'){
            PayOrder_window.hideReportWindow();
            //设置光标
            PayOrder.getFocusMethod();
        }
        //回车键
        if(key == '13'){
            if(PayOrder_key.REPORT_TYPE == "0"){
                PayOrder_window.hideReportWindow();
                PayOrder_window.checkIsBhSetted();
            }else if(PayOrder_key.REPORT_TYPE == "1"){
                PayOrder_window.hideReportWindow();
                PayOrder.getFocusMethod();
            }else if(PayOrder_key.REPORT_TYPE == "2"){
                PayOrder_window.hideReportWindow();
                PayOrder.standardPost($("#return_url").val(), PayOrder_QR.payCenterParams);
                var book_flag= $("#book_type").val();
            }else if(PayOrder_key.REPORT_TYPE == "3"){
                PayOrder_window.hideReportWindow();
                PayOrder_window.clearResetWindow();
                PayOrder_window.showResetWindow();
            }else if(PayOrder_key.REPORT_TYPE == "4"){
                PayOrder_window.hideReportWindow();
                PayOrder_window.clearResetWindow();
                PayOrder.getFocusMethod();
            }else if(PayOrder_key.REPORT_TYPE == "5"){
                PayOrder_window.hideReportWindow();
                PayOrder_window.clearResetWindow();
                PayOrder_window.showResetWindow();
            }else if(PayOrder_key.REPORT_TYPE == "6"){
                PayOrder_window.hideReportWindow();
                PayOrder.getFocusMethod();
            }else if(PayOrder_key.REPORT_TYPE == "7"){
                PayOrder_window.hideReportWindow();
                PayOrder_window.showVsmsWindow();
            }else if(PayOrder_key.REPORT_TYPE == "8"){
                PayOrder_window.hideReportWindow();
                PayOrder_window.showVsmsWindow();
            }
        }
    },

    //支付密码错误弹窗
    bhtErrorAction : function(key,btn_id){
        //返回键
        if(key == '8'){
            PayOrder_window.hideReportWindow();
            //设置光标
            PayOrder.getFocusMethod();
        }
        //回车键
        if(key == '13') {
            if (btn_id == "buttonRet_bh_btn") {
                PayOrder_window.hideNewPassWindow();
                PayOrder_window.showResetWindow();
            }else if(btn_id=="button_bh_btn"){
                PayOrder_window.hideNewPassWindow();
                $("#password").html("");
                PayOrder.PASSWORD_COUNT = "";
                $("#confirm_div").show();
                $(".focuse").removeClass("focuse");
                $("#password").addClass("focuse");
                PayOrder_key.keyCode = "2";
            }
        }
        //左点击事件
        if(key == '37' || key == '39' || key == '38' || key == '40') {
            if (btn_id == "buttonRet_bh_btn") {
                $("#buttonRet_bh_btn").removeClass("focuse");
                $("#button_bh_btn").addClass("focuse");
            }
            if(btn_id == "button_bh_btn"){
                $("#button_bh_btn").removeClass("focuse");
                $("#buttonRet_bh_btn").addClass("focuse");
            }
        }
    },
    //重置密码按键操作
    resetAction : function(key,btn_id){
        //返回键
        if(key == '8'){
            if(btn_id == 'newPassword'){
                var newPassword = $("#newPassword").html();
                if(newPassword!=""){
                    var change_count = PayOrder.NEW_PASSWORD_COUNT;
                    change_count = change_count.substring(0, change_count.length-1);
                    PayOrder.NEW_PASSWORD_COUNT = change_count;
                    var pwd = "";
                    for(var i=0;i<PayOrder.NEW_PASSWORD_COUNT.length;i++){
                        pwd += "●";
                    }
                    $("#newPassword").html(pwd);
                }
            }
            if(btn_id == "smsText" && PayOrder.SMS_COUNT != "") {
                var change_count = PayOrder.SMS_COUNT;
                change_count = change_count.substring(0, change_count.length-1);
                PayOrder.SMS_COUNT = change_count;
                $("#smsText").html(change_count);
                return false;
            }
            PayOrder_window.hideResetWindow();
            //设置光标
            PayOrder.getFocusMethod();
        }
        //回车键
        if(key == '13'){
            if(btn_id =="sendSmsBtn"){
                if(PayOrder.READ_SECOND == "1") {
                    return false;
                }else{
                    PayOrder_window.hideResetWindow();
                    PayOrder.sendRandomSmsForReset(btn_id);
                    PayOrder.setDisabledTime(btn_id,60);
                }
            }else if(btn_id=="reset_confirm_btn"){
                PayOrder_window.hideResetWindow();
                var newPassword = PayOrder.NEW_PASSWORD_COUNT;
                if(newPassword == null || newPassword == " " || newPassword == "" || newPassword == undefined){
                    newPassword = $("#newPassword").val();
                }
                var smsText = $("#smsText").html();
                if(newPassword == null || newPassword == " " || newPassword == "" || newPassword == undefined){
                    PayOrder_window.showReportWindow("密码不能为空！", "5");
                }else{
                    PayOrder.authRandomSms();
                }
                $("#newPassword").val("");
                $("#smsText").val("");
            }else if(btn_id=="reset_cancel_btn"){
                PayOrder_window.hideResetWindow();
                PayOrder_window.clearResetWindow();
                PayOrder.getFocusMethod();
                $("#newPassword").val("");
                $("#smsText").val("");
            }else if(btn_id =="newPassword" || btn_id =="smsText"){
                $("#newPassword").removeClass("focuse");
                $("#smsText").removeClass("focuse");
                PayOrder_key.DEL_FROM_ID=btn_id;
                $("#keyboard").show();
                $("#num1").addClass("focuse");
            }else{
                var btn_value = $("#"+btn_id+"").attr('value');
                if(btn_value == "12"){//取消
                    $("#"+btn_id).removeClass("focuse");
                    if(PayOrder_key.DEL_FROM_ID == "newPassword"){
                        $("#newPassword").addClass("focuse");
                    }
                    if(PayOrder_key.DEL_FROM_ID == "smsText"){
                        $("#smsText").addClass("focuse");
                    }
                    //收起软键盘
                    PayOrder_window.keyboardWindow();
                }else if(btn_value == "10"){//清除
                    PayOrder.editPwdCode(PayOrder_key.DEL_FROM_ID);
                }else{
                    PayOrder.addPwdCode(btn_value,PayOrder_key.DEL_FROM_ID);
                }
            }
        }

        //左 右 点击事件
        if(key == '37' || key == '39'){
            //验证码输入框和获取验证码，左右摇摆
            if(btn_id == "sendSmsBtn"){
                $("#sendSmsBtn").removeClass("focuse");
                $("#smsText").addClass("focuse");
            }
            if(btn_id == "smsText"){
                $("#smsText").removeClass("focuse");
                $("#sendSmsBtn").addClass("focuse");
            }
            //确认和取消，左右摇摆
            if(btn_id == "reset_cancel_btn"){
                $("#reset_cancel_btn").removeClass("focuse");
                $("#reset_confirm_btn").addClass("focuse");
            }
            if(btn_id == "reset_confirm_btn"){
                $("#reset_confirm_btn").removeClass("focuse");
                $("#reset_cancel_btn").addClass("focuse");
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //上点击事件
        if(key == '38'){
            if(btn_id == "newPassword"){
                $("#newPassword").removeClass("focuse");
                $("#sendSmsBtn").addClass("focuse");
            }
            if(btn_id == "reset_confirm_btn" || btn_id == "reset_cancel_btn"){
                $("#reset_confirm_btn").removeClass("focuse");
                $("#reset_cancel_btn").removeClass("focuse");
                $("#newPassword").addClass("focuse");
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }
        }
        //下点击事件
        if(key == '40'){
            if(btn_id == "smsText" || btn_id == "sendSmsBtn"){
                $("#smsText").removeClass("focuse");
                $("#sendSmsBtn").removeClass("focuse");
                $("#newPassword").addClass("focuse");
            }
            if(btn_id == "newPassword"){
                $("#newPassword").removeClass("focuse");
                $("#reset_confirm_btn").addClass("focuse");
            }
            if(btn_id == "reset_confirm_btn" || btn_id == "reset_cancel_btn"){
                if(PayOrder_key.DEL_FROM_ID!=""){
                    $("#reset_confirm_btn").removeClass("focuse");
                    $("#reset_cancel_btn").removeClass("focuse");
                    $("#num1").addClass("focuse");
                }
            }
            if(btn_id.indexOf("num") != -1){
                //软键盘按键
                PayOrder_key.keyboard_Orso(btn_id,event.keyCode);
            }

        }

        //输入框
        if(btn_id == "newPassword") {
            var count = getReomteCount(event.keyCode);
            if(count != "" && PayOrder.NEW_PASSWORD_COUNT.length<6) {
                PayOrder.NEW_PASSWORD_COUNT = PayOrder.NEW_PASSWORD_COUNT + count;
                var pwd = "";
                for(var i=0;i<PayOrder.NEW_PASSWORD_COUNT.length;i++){
                    pwd += "●";
                }
                $("#newPassword").html(pwd);
                $("#newPassword").val(PayOrder.NEW_PASSWORD_COUNT);
            }
            return false;
        }
        //输入框
        if(btn_id == "smsText") {
            var count = getReomteCount(event.keyCode);
            if(count != "" && PayOrder.SMS_COUNT.length<6) {
                PayOrder.SMS_COUNT = PayOrder.SMS_COUNT + count;
                $("#smsText").html(PayOrder.SMS_COUNT);
            }
            return false;
        }
    },
    //软键盘按键
    keyboard_Orso : function(btn_id,keyCode){
        $("#"+btn_id).removeClass("focuse");

        var btn_value = $("#"+btn_id).attr('value');
        //零单独做处理
        if(btn_value == "0"){
            if(keyCode == '37'){
                $("#num10").addClass("focuse");
            }
            if(keyCode == '39'){
                $("#num12").addClass("focuse");
            }
            if(keyCode == '38'){
                $("#num8").addClass("focuse");
            }
            if(keyCode == '40'){
                $("#"+btn_id).addClass("focuse");
            }
            return;
        }

        //左
        if(keyCode == '37' && btn_value != "1" && btn_value != "4" && btn_value != "7" && btn_value != "10"){
            btn_value = Number(btn_value) - 1;
            if(btn_value == "11"){
                $("#num0").addClass("focuse");
                return;
            }
            $("#num"+btn_value).addClass("focuse");
            return;
        }

        //右
        if(keyCode == '39' && btn_value != "3" && btn_value != "6" && btn_value != "9" && btn_value != "12"){
            btn_value = Number(btn_value) + 1;
            if(btn_value == "11"){
                $("#num0").addClass("focuse");
                return;
            }
            $("#num"+btn_value).addClass("focuse");
            return;
        }

        //上
        if(keyCode == '38'){
            if(btn_value == "1" || btn_value == "2" || btn_value == "3"){
                if(PayOrder_key.DEL_FROM_ID == "password"){
                    $("#confirm_btn").addClass("focuse");
                }
                if(PayOrder_key.DEL_FROM_ID == "v_sms_Text"){
                    $("#v_sms_confirm_btn").addClass("focuse");
                }
                if(PayOrder_key.DEL_FROM_ID == "newPassword" || PayOrder_key.DEL_FROM_ID == "smsText"){
                    $("#reset_confirm_btn").addClass("focuse");
                }
                return;
            }
            btn_value = Number(btn_value) - 3;
            $("#num"+btn_value).addClass("focuse");
            return;
        }

        //下
        if(keyCode == '40' && btn_value != "10" && btn_value != "0" && btn_value != "12"){
            btn_value = Number(btn_value) + 3;
            if(btn_value == "11"){
                $("#num0").addClass("focuse");
                return;
            }
            $("#num"+btn_value).addClass("focuse");
            return;
        }
        $("#"+btn_id).addClass("focuse");
    },

    //订购首页按键操作
    indexUserBehavior : function(btn_id){
        //用户行为轨迹 :账单支付确定按钮
        if("account_pay" == btn_id){
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num11) ;
        }
    },
    //二次确认按键操作
    manyUserBehavior : function(btn_id){
        if(btn_id =="buttonCel_btn" ){
            //用户行为轨迹 :二次弹窗_取消按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num12) ;
        }
        else if(btn_id =="button_btn" ){
            //用户行为轨迹 :二次弹窗_确定按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num13) ;
        }
    },
    bhUserBehavior : function(btn_id){
        if(btn_id =="password" ){
            //用户行为轨迹 :消费密码_密码文本框
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num14) ;
        }
        else if(btn_id =="confirm_btn" ){
            //用户行为轨迹 :消费密码_确定按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num15) ;
        }
        else if(btn_id =="cancel_btn" ){
            //用户行为轨迹 :消费密码_取消按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num16) ;
        }
    },
    resetUserBehavior : function(btn_id){
        if(btn_id =="button_bh_btn" ){
            //用户行为轨迹 :消费密码错误提示弹窗_确定按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num17) ;
        }
        else if(btn_id =="buttonRet_bh_btn" ){
            //用户行为轨迹 :消费密码错误提示弹窗_重置密码按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num18) ;
        }

        else if(btn_id =="sendSmsBtn" ){
            //用户行为轨迹 :重置消费密码_发送验证码按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num19) ;
        }
        else if(btn_id =="smsText" ){
            //用户行为轨迹 :重置消费密码_验证码文本框
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num20) ;
        }
        else if(btn_id =="newPassword" ){
            // 用户行为轨迹 :重置消费密码_消费密码文本框
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num21) ;
        }
        else if(btn_id =="reset_confirm_btn" ){
            //用户行为轨迹 :重置消费密码_确定按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num22) ;
        }
        else if(btn_id =="reset_cancel_btn" ){
            //用户行为轨迹 :重置消费密码_取消按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num23) ;
        }
    },
    bh_sms_Behavior : function(btn_id){
        if(btn_id =="button_bh_btn" ){
            //用户行为轨迹 :订购页面_支付密码短信认证_确定按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num36) ;
        }
        else if(btn_id =="buttonRet_bh_btn" ){
            //用户行为轨迹 :订购页面_支付密码短信认证_取消按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num37) ;
        }

        else if(btn_id =="sendSmsBtn" ){
            //用户行为轨迹 :订购页面_支付密码短信认证_验证码发送按钮
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num38) ;
        }
        else if(btn_id =="smsText" ){
            //用户行为轨迹 :订购页面_支付密码短信认证_验证码输入框
            PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num39) ;
        }
    },
    //系统异常按键操作
    errorUserBehavior : function(btn_id){
        //告警类型，0：消费密码告警 1：异常告警 2：订购成功告警 3：重置密码失败 4：重置密码成功 5：发送验证码
        if(PayOrder_key.REPORT_TYPE == "1"){
            if( btn_id =="report_btn" ){
                // 用户行为轨迹 :订购异常告警弹窗_确定按钮
                PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num24) ;
            }
        }
        else if(PayOrder_key.REPORT_TYPE == "2"){
            if( btn_id =="report_btn" ){
                // 用户行为轨迹 :订购成功弹窗_确定按钮
                PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num25) ;
            }
        }
        else if(PayOrder_key.REPORT_TYPE == "3"){
            if( btn_id =="report_btn" ){
                // 用户行为轨迹 :重置消费密码失败结果弹窗_确定按钮
                PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num26) ;
            }
        }
        else if(PayOrder_key.REPORT_TYPE == "4"){
            if( btn_id =="report_btn" ){
                // 用户行为轨迹 :重置消费密码成功结果弹窗_确定按钮
                PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num27) ;
            }
        }
        else if(PayOrder_key.REPORT_TYPE == "5"){
            if( btn_id =="report_btn" ){
                // 用户行为轨迹 :发送验证码结果弹窗_确定按钮
                PayOrder.USER_BEHAVIORS.push(IptvUserBehaviorEnum.Num28) ;
            }
        }
    },
};

var PayOrder_window = {

    //校验是否超过消费限额
    checkIsSetConsumptionPwd : function(){
        var isSetConsumptionPwd = $("#is_set_consumption_pwd").val();
        if(isSetConsumptionPwd == "1"){
            //显示支付密码确认弹窗
            $("#div_box").show();
            $(".focuse").removeClass("focuse");
            $("#set_consumption_pwd").show();
            $("#set_consumption_pw_confirm_btn").addClass("focuse");
            return true;
        }
        return false;
    },
    //校验是否已经设置支付密码
    checkIsBhSetted : function(){
        $("#div_box").show();
        $("#password").html("");
        PayOrder.PASSWORD_COUNT = "";
        $("#confirm_div").show();
        $(".focuse").removeClass("focuse");
        $("#password").addClass("focuse");
        PayOrder_key.keyCode = "2";
    },

    //关闭支付密码确认弹窗
    hideBhWindow : function(){
        PayOrder_key.keyCode = "0";
        //收起软键盘
        PayOrder_window.keyboardWindow();
        $("#confirm_div").hide();
    },

    //显示报告弹窗
    showReportWindow : function(msg, report_type){
        $("#div_box").show();
        $("#report_div").show();
        $("#report_msg").html(msg);
        $(".focuse").removeClass("focuse");
        $("#report_btn").addClass("focuse");
        PayOrder_key.keyCode = "99";
        PayOrder_key.REPORT_TYPE=report_type;
    },

    //关闭报告弹窗
    hideReportWindow : function(){
        $("#div_box").hide();
        PayOrder_key.keyCode = "0";
        $("#report_div").hide();
        $("#button_bh_div").hide();
    },

    //二次确认弹窗
    showSecConfirmWin : function(){
        $("#div_box").show();
        $("#button_msg").html("您确认购买"+$("#product_name").val() + "吗?");
        var sec_confirm_info = $("#sec_confirm_info").val();
        if(sec_confirm_info!=null && sec_confirm_info!=""){
            $("#button_msg").html(sec_confirm_info);
        }
        $(".focuse").removeClass("focuse");
        $("#button_div").show();
        $("#buttonCel_btn").addClass("focuse");

        PayOrder_key.keyCode = "1";
    },

    //关闭二次确认弹窗
    hideSecConfirmWin : function(){
        PayOrder_key.keyCode = "0";
        $("#button_div").hide();
    },

    //支付密码错误弹窗
    showResetPwdSettedWindow : function(msg){
        $("#div_box").show();
        $("#button_bh_div").show();
        $("#button_bh_msg").html(msg);
        $(".focuse").removeClass("focuse");
        $("#button_bh_btn").addClass("focuse");
        PayOrder_key.keyCode = "3";
    },

    //关闭支付密码错误弹窗
    hideNewPassWindow : function(){
        PayOrder_key.keyCode = "0";
        $("#button_bh_div").hide();
    },

    //显示重置密码弹窗
    showResetWindow : function(){
        $("#div_box").show();
        $("#button_reset_div").show();
        $(".focuse").removeClass("focuse");
        $("#sendSmsBtn").addClass("focuse");
        PayOrder_key.keyCode = "4";
    },
    //关闭重置密码弹窗
    hideResetWindow : function(){
        //收起软键盘
        PayOrder_window.keyboardWindow();
        $("#button_reset_div").hide();
        PayOrder_key.keyCode = "0";
    },
    //关闭重置密码弹窗
    hideResetBhWindow : function(){
        $("#button_reset_bh_div").hide();
        PayOrder_key.keyCode = "0";
    },
    //清除重置数据
    clearResetWindow : function(){
        $("#smsText").html("");
        $("#newPassword").html("");
        PayOrder.NEW_PASSWORD_COUNT="";
        PayOrder.SMS_COUNT="";
    },
    //软键盘收起
    keyboardWindow : function(){
        $("#keyboard").hide();
        PayOrder_key.DEL_FROM_ID="";
    },

    //显示验证码订购弹窗
    showVsmsWindow : function(){
        $("#div_box").show();
        $("#bh_sms_div").show();
        $(".focuse").removeClass("focuse");
        $("#v_sms_Text").html("");
        $("#v_sms_Text").addClass("focuse");
        PayOrder_key.keyCode = "5";
    },
    //关闭验证码订购弹窗
    hideVsmsWindow : function(){
        //收起软键盘
        PayOrder_window.keyboardWindow();
        $("#bh_sms_div").hide();
        PayOrder_key.keyCode = "0";
    },
};

var PayOrder_QR = {
    payCenterParams :"",
    jh_pay : "",
    wx_pay : "",

    //查询是否支付完成，然后每秒查询一次支付状态
    checkOrderStatus : function(){
        var id = setInterval(function(){
            var params = {
                RECHARGE_LOG_ID : $("#order_id").val(),
                AMOUNT : $("#amount").val()
            }
            Service.excuteNoLoading("CHECK_RECHARGE", false, params, function(reply) {
                if(reply.flag == "0"){
                    if(reply.RECHARGE_STATUS == "1"){
                        var book_flag= $("#book_type").val();;
                        if(undefined != book_flag && null != book_flag && "3" == book_flag){
                            PayOrder_window.showReportWindow("预约成功！","2");
                        }else{
                            PayOrder_window.showReportWindow("订购成功！","2");
                        }
                        var payCenterParams = {};
                        payCenterParams['notify_id'] = reply.NOTIFY_ID;
                        payCenterParams['timestamp'] = reply.TIMESTAMP;
                        payCenterParams['data'] = reply.DATA;
                        payCenterParams['sign'] = reply.SIGN;
                        PayOrder_QR.payCenterParams = payCenterParams;
                        //第三方支付成功
                        setTimeout(function () {
                            PayOrder_window.hideReportWindow();
                            PayOrder.standardPost($("#return_url").val(), PayOrder_QR.payCenterParams);
                        }, 3000);
                        clearInterval(id);
                    }
                }else{
                    PayOrder_window.showReportWindow("查询充值状态失败，请与客服联系！","1");
                    clearInterval(id);
                }
            });
        }, 1000);
    },

    //创建支付二维码
    createQrCode : function(){
        var req = PayOrder.getParams();
        req['jh_pay'] = PayOrder_QR.jh_pay || "";
        req['wx_pay'] = PayOrder_QR.wx_pay || "";
        Service.excuteNoLoading("ONLINE_PAY", false, req, function(reply) {
            if(reply.flag == "0"){
                if(reply.JH_CODE_URL){
                    //聚合码
                    PayOrder_QR.createQrCodeImage(PayOrder_QR.jh_pay, reply.JH_CODE_URL);
                    //查询是否支付完成，然后每秒查询一次支付状态
                    PayOrder_QR.checkOrderStatus();
                }
                //第三方扫码支付
                else if(reply.WX_CODE_URL){
                    PayOrder_QR.createQrCodeImage(PayOrder_QR.wx_pay, reply.WX_CODE_URL);
                    //查询是否支付完成，然后每秒查询一次支付状态
                    PayOrder_QR.checkOrderStatus();
                }
            }else{
                //聚合
                if(PayOrder_QR.jh_pay){
                    $("#jh_pay").remove();
                }
                //连续包月微信签约代扣
                else if(PayOrder_QR.wx_pay){
                    $("#wx_pay").remove();
                }
                //删除中间竖线
                $("#pay_mode_1").removeAttr("style");
                $("#account_pay_txt").show();
            }
        });

    },
    //二维码展示
    createQrCodeImage : function(payType,codeUrl){
        if(payType!="jh_pay" && payType!="wx_pay"){
            $("#" + payType + "_icon").attr("src", "/images/" + payType + "_icon.png");
        }
        $("#" + payType + "_qrCode").html("");
        $("#" + payType + "_icon").css("position","absolute");
        jQuery("#" + payType + "_qrCode").qrcode({
            width:200,
            height:200,
            correctLevel:1,
            text:codeUrl
        });
        var margin = ($("#" + payType + "_qrCode").height() - $("#" + payType + "_icon").height()) / 2; //控制Logo图标的位置，50为白边宽度乘以2
        $("#" + payType + "_icon").css("margin",margin);
    },

};

var PayOrder = {

    //支付密码
    PASSWORD_COUNT:"",
    //新密码
    NEW_PASSWORD_COUNT:"",
    //控制重复提交
    INVOKING : false,
    //验证码
    SMS_COUNT : "",
    //是否读秒
    READ_SECOND:"0",
    USER_BEHAVIORS : new Array(),
    init : function(){
        //清空支付密码
        PayOrder.eventBinding();

        //按键操作绑定
        PayOrder.listenKey();

        //判断显示的支付方式
        PayOrder.showPayList();

        //绑定事件
        PayOrder.bindFocus();

        //背景图切换
        PayOrder.getBackgroundImg();

        //校验用户手机号是否存在，存在执行弹窗,手机号码获取
        PayOrder.sendUserTelephoneMsg();

        //默认选中第一种显示的支付方式
        PayOrder.getFocusMethod();

        //订购量统计
        PayOrder.getDataCountMethod();
    },

    //清空支付密码
    eventBinding : function(){
        $("#password").focus(function(){
            $(this).html("");
        })
    },

    //背景图切换
    getBackgroundImg : function(){
        var picture_name=$("#picture_name").val();
        if( picture_name !=undefined && picture_name!="null" && picture_name!="" && picture_name!=null){
            //默认背景图片样式
            $("body").css("background","url("+picture_name+") no-repeat #176b7d");
            $("body").css("background-size","cover");
        }

    },

    //显示的支付方式
    showPayList : function(){
        var pay_mode =  $("#pay_mode").val() || "";

        //账单支付
        if(pay_mode.indexOf("ZD_NATIVE") > -1){
            $("#account_pay_zd").show();
        }else{
            //删除中间竖线
            //$("#pay_mode_1").removeAttr("style");
        }

        //获取资费信息
        var pricing_type =  $("#pricing_type").val() || "";
        //FIXME 聚合二维码，1秒钟查询一次支付状态（非账单支付） 不为连续包月时显示
        if(pay_mode.indexOf("WX_NATIVE") > -1 && 2 !=pricing_type  && 16 !=pricing_type  && 17 !=pricing_type){
            $("#jh_pay").show();
            PayOrder_QR.jh_pay = "jh_pay";
            //创建二维码
            PayOrder_QR.createQrCode();
        }
        //连续包月第三方支付
        else if(pay_mode.indexOf("WX_NATIVE") > -1 && (2 ==pricing_type|| 16 ==pricing_type || 17 ==pricing_type)){
            $("#jh_pay").hide();
            $("#wx_pay").show();
            PayOrder_QR.wx_pay = "wx_pay";
            //创建二维码
            PayOrder_QR.createQrCode();
        }else{
            //删除中间竖线
            $("#pay_mode_1").removeAttr("style");
            $("#account_pay_txt").show();
        }
    },

    //创建订购实例（账单支付或者积分支付），调用的是支付回调接口
    createOrderZD : function(reply){
        if(reply.flag == "0"){
            PayOrder.INVOKING = false;
            var payCenterParams = {};
            payCenterParams['notify_id'] = reply.NOTIFY_ID;
            payCenterParams['timestamp'] = reply.TIMESTAMP;
            payCenterParams['data'] = reply.DATA;
            payCenterParams['sign'] = reply.SIGN;
            PayOrder_QR.payCenterParams = payCenterParams;
            //判断是否订购完成弹窗
            PayOrder.judgeCompleteWindow(reply.NOTIFY_ID,reply.TIMESTAMP,reply.DATA,reply.SIGN);
        }else{
            PayOrder.INVOKING = false;
            PayOrder_window.showReportWindow(reply.ERR_MSG, "1");
            return;
        }
    },

    //记录订购关系
    createOrder : function(reply){
        var req = PayOrder.getParams();
        Service.excute("record_order", false, req, function(reply) {
            //支付完成
            if(reply.flag == "0"){
                PayOrder.INVOKING = false;
                var payCenterParams = {};
                payCenterParams['notify_id'] = reply.NOTIFY_ID;
                payCenterParams['timestamp'] = reply.TIMESTAMP;
                payCenterParams['data'] = reply.DATA;
                payCenterParams['sign'] = reply.SIGN;
                PayOrder_QR.payCenterParams = payCenterParams;
                //判断是否订购完成弹窗
                PayOrder.judgeCompleteWindow(reply.NOTIFY_ID,reply.TIMESTAMP,reply.DATA,reply.SIGN);
            }else{
                PayOrder.INVOKING = false;
                PayOrder_window.showReportWindow(reply.ERR_MSG, "1");
                return;
            }
        });
    },

    //二次确认短信发送--非法订购
    sendConfirmMsg : function(){
        var req = PayOrder.getParams();
        Service.excute("record_order", false, req, function(reply) {
            //支付完成
            if(reply.flag == "0"){
                PayOrder.INVOKING = false;
                var payCenterParams = {};
                payCenterParams['notify_id'] = reply.NOTIFY_ID;
                payCenterParams['timestamp'] = reply.TIMESTAMP;
                payCenterParams['data'] = reply.DATA;
                payCenterParams['sign'] = reply.SIGN;
                PayOrder_QR.payCenterParams = payCenterParams;
                //判断是否订购完成弹窗
                PayOrder.judgeCompleteWindow(reply.NOTIFY_ID,reply.TIMESTAMP,reply.DATA,reply.SIGN);
            }else{
                PayOrder.INVOKING = false;
                PayOrder_window.showReportWindow(reply.ERR_MSG, "1");
                return;
            }
        });
    },

    //二次确认短信发送
    orderConfirmMsg : function(){
        var req = PayOrder.getParams();
        req['pay_type'] = "account_pay";
        req['is_new'] = "F";
        Service.excute("SEND_SEC_CONFIRM_MSG", false, req, function(reply) {
            console.log(reply);
            if(reply.flag == "0"){
                PayOrder_window.showReportWindow(reply.SMS_CONFIRM_POP, "6");
            }else{
                PayOrder_window.showReportWindow(reply.ERR_MSG, "1");
                return;
            }
        });
    },

    //校验用户手机号是否存在，存在执行弹窗
    sendUserTelephoneMsg : function(){
        var params = {
            user_id: $("#user_id").val(),
            md_user_id: $("#md_user_id").val(),
            operate_source:"payOrder"
        }
        Service.excute("QRY_USER_INFO_FOR_RESET", false, params, function (reply) {
            if (reply.flag == "0") {
                $("#telephone_des").html("手机号:" + reply.TELEPHONE_DES);
                //$("#telephone").val(reply.TELEPHONE);
                $("#telephone").val(reply.TELEPHONE_DES);
                $("#senSmstelephone_des").html("手机号:" + reply.TELEPHONE_DES);
                $("#senSmstelephone").val(reply.TELEPHONE_DES);
            } else {
                PayOrder_window.showReportWindow(reply.ERR_MSG, "1");
                return false;
            }
        });
    },

    //订购成功返回参数封装
    standardPost:function(url,args){
        $(".focuse").removeClass("focuse");
        var body = $(document.body),
            form = $("<form method='post'></form>"),input;
        form.attr({"action":url});
        $.each(args,function(key,value){
            input = $("<input type='hidden'>");
            input.attr({"name":key});
            input.val(value);
            form.append(input);
        });

        form.appendTo(body);
        form.submit();
        form.remove();
    },

    //收集页面参数
    getParams : function(){
        var params = {
        }
        $("#param_form").find("input[type='text']").each(function(){
            var id = $(this).attr("id");
            params[id] = $(this).val();
        });
        return params;
    },

    //校验密码
    validateBhPsw : function(password){
        var params = {
            USER_ID : $("#user_id").val(),
            ORDER_ID : $("#order_id").val(),
            PRODUCT_ID : $("#product_id").val(),
            PASSWORD : password
        }
        Service.excute("VALIDATE_PSW",false,params,function(reply){
            if(reply.flag == "0"){
                var resultCode = reply.RESULT_CODE;
                if(resultCode == "2004"){
                    PayOrder_window.showResetPwdSettedWindow("密码不正确！");
                    return false;
                }else if(resultCode ==  "0"){
                    // 避免重复提交
                    if(PayOrder.INVOKING){
                        return;
                    }
                    PayOrder.INVOKING = true;
                    var req = PayOrder.getParams();
                    req['pay_type'] = "account_pay";
                    req['isPopupWindow'] = "2";
                    req['userPasswod'] = $("#v_sms_Text").html();
                    Service.excute("CREATE_ORDER_ENCRYPT", false, req, function(reply) {
                        if(reply.flag == "0"){
                            req['userCreateOrder'] = reply.USERCREATEORDER;
                            Service.excute("CREATE_ORDER", false, req, function(reply) {
                                //支付完成
                                PayOrder.createOrderZD(reply);
                            });
                        }
                    });
                }else{
                    PayOrder_window.showReportWindow("系统错误，请联系管理员！", "1");
                    return false;
                }
            }else if(reply.flag == "-1"){
                PayOrder_window.showReportWindow("网络异常，请稍后再试", "1");
                return false;
            }
        });
    },

    //按键操作
    listenKey : function(){
        $(document).keydown(function (event) {
            var btn_id = $(".focuse").attr("id");
            var key = event.keyCode;
            if (PayOrder_key.keyCode == "0") {
                PayOrder_key.indexUserBehavior(btn_id);
                PayOrder_key.indexAction(key,btn_id);
                return false;
            }
            if (PayOrder_key.keyCode == "1") {
                PayOrder_key.manyUserBehavior(btn_id);
                if(key == '13' && btn_id == "button_btn") {
                    //支付完成
                    // 避免重复提交
                    if(PayOrder.INVOKING){
                        return;
                    }
                    PayOrder.sendSecConfirmInfo();
                    PayOrder.INVOKING = true;
                    var req = PayOrder.getParams();
                    req['pay_type'] = "account_pay";
                    req['isPopupWindow'] = "4";
                    req['userPasswod'] = $("#v_sms_Text").html();
                    Service.excute("CREATE_ORDER_ENCRYPT", false, req, function(reply) {
                        if(reply.flag == "0"){
                            req['userCreateOrder'] = reply.USERCREATEORDER;
                            Service.excute("CREATE_ORDER", false, req, function(reply) {
                                //支付完成
                                PayOrder.createOrderZD(reply);
                            });
                        }
                    });
                    PayOrder_window.hideSecConfirmWin();
                }else{
                    PayOrder_key.manyAction(key,btn_id);
                }
                return false;
            }
            if (PayOrder_key.keyCode == "2") {
                PayOrder_key.bhUserBehavior(btn_id);
                PayOrder_key.bhAction(key,btn_id);
                return false;
            }
            if (PayOrder_key.keyCode == "3") {
                PayOrder_key.resetUserBehavior(btn_id);
                PayOrder_key.bhtErrorAction(key,btn_id);
                return false;
            }
            if (PayOrder_key.keyCode == "4") {
                PayOrder_key.resetUserBehavior(btn_id);
                PayOrder_key.resetAction(key,btn_id);
                return false;
            }
            if (PayOrder_key.keyCode == "5") {
                PayOrder_key.bh_sms_Behavior(btn_id);
                PayOrder_key.bh_sms_Action(key,btn_id);
                return false;
            }
            if (PayOrder_key.keyCode == "99") {
                PayOrder_key.errorUserBehavior(btn_id);
                PayOrder_key.errorAction(key,btn_id);
                return false;
            }
            return false;
        })

    },

    //待验证功能
    bindFocus : function(){
        $(".mode-btn").bind("focuse", function(){
            $(".focuse").removeClass("focuse");
            $(this).addClass("focuse");
        });
    },
    //发送随机验证码
    sendRandomSmsForReset : function(btn_id){
        var params = {
            user_id : $("#user_id").val(),
            telephone : "telephone",
            type : "reset"
        }
        Service.excute("SEND_RANDOM_SMS_RESET",false,params,function(reply){
            if(reply.flag == "0"){
                var msg = "尊敬的用户，您好。验证码已发送至您"+$("#telephone_des").html().substring(4)+"手机号，请查收。";
                if("sendSmsBtn" == btn_id){
                    PayOrder_window.showReportWindow(msg, "5");
                }else{
                    PayOrder_window.showReportWindow(msg, "7");
                }
            }else{
                PayOrder_window.showReportWindow("网络异常，请稍后再试", "1");
                return false;
            }
        });
    },
    sendSecConfirmInfo : function(btn_id){
        var params = {
            user_id : $("#user_id").val(),
            telephone : "telephone",
            order_id : $("#order_id").val(),
            product_id : $("#product_id").val()
        }
        Service.excute("SEND_SEC_CONFIRM_INFO",false,params,function(reply){
            if(reply.flag == "0"){

            }else{
                PayOrder_window.showReportWindow("网络异常，请稍后再试", "1");
                return false;
            }
        });
    },
    setDisabledTime : function(text,time) {
        PayOrder.READ_SECOND = "1";
        var btn = $("#"+text);
        var originBtnValue = btn.text();
        btn.text(time <= 0 ? originBtnValue : ("" + (time) + "s"));
        var hander = setInterval(function() {
            if (time <= 0) {
                clearInterval(hander);
                btn.text(originBtnValue);
                PayOrder.READ_SECOND = "0";
            } else {
                btn.text("" + (time--) + "s");
            }
        }, 1000);
    },
    //校验验证码
    authRandomSms : function(){
        var me = this;
        var UserID =  $("#user_id").val();
        //var telephone = $("#telephone").val();
        var random_sms = $("#smsText").html();
        if(random_sms == "" || random_sms == undefined) {
            PayOrder_window.showReportWindow("请输入验证码！", "3");
            return false;
        }
        if(random_sms.length!="6") {
            PayOrder_window.showReportWindow("请输入长度为6的验证码！", "3");
            return false;
        }
        //重置消费密码
        var params = {
            USER_ID : $("#user_id").val(),
            NEW_PAS : PayOrder.NEW_PASSWORD_COUNT,
            VALI_CODE : random_sms,
            TELEPHONE : "telephone"
        }
        Service.excute("SMS_RESETPASS_PASS",false,params,function(reply){
            if(reply.flag == 0){
                PayOrder_window.showReportWindow("重置密码成功！", "4");
            }else{
                PayOrder_window.showReportWindow("验证码错误,请重新输入!", "3");
                return false;
            }
        });
    },
    //校验订购验证码是否正确
    resetVbhsms : function(){
        var random_sms = $("#v_sms_Text").html();
        if(random_sms == "" || random_sms == undefined) {
            PayOrder_window.showReportWindow("请输入验证码！", "8");
            return false;
        }
        if(random_sms.length!="6") {
            PayOrder_window.showReportWindow("请输入长度为6的验证码！", "8");
            return false;
        }

        var params = {
            user_id : $("#user_id").val(),
            telephone : "telephone",
            order_id : $("#order_id").val(),
            random_sms: random_sms
        }
        Service.excute("SMS_AUTH_RANDOM",false,params,function(reply){
            if(reply.flag == "0"){
                //支付完成
                // 避免重复提交
                if(PayOrder.INVOKING){
                    return;
                }
                PayOrder.INVOKING = true;
                var req = PayOrder.getParams();
                req['pay_type'] = "account_pay";
                req['isPopupWindow'] = "3";
                req['userPasswod'] = $("#v_sms_Text").html();
                Service.excute("CREATE_ORDER_ENCRYPT", false, req, function(reply) {
                    if(reply.flag == "0"){
                        req['userCreateOrder'] = reply.USERCREATEORDER;
                        Service.excute("CREATE_ORDER", false, req, function(reply) {
                            //支付完成
                            PayOrder.createOrderZD(reply);
                        });
                    }
                });
            }else if(reply.flag == "-1"){
                PayOrder_window.showReportWindow("验证码错误，请重新输入！", "8");
                return false;
            }
        });
    },

    addPwdCode : function(sms,id){
        var smsText = $("#"+id+"").val();
        if(smsText != null && smsText != "" && smsText != undefined){
            if(smsText.length<6){
                PayOrder_key.SMS_COUNT =   PayOrder_key.SMS_COUNT + sms;
            }
        }else{
            PayOrder_key.SMS_COUNT = ""+sms;
        }
        var pwd = "";
        for(var i=0;i<PayOrder_key.SMS_COUNT.length;i++){
            pwd += "●";
        }
        $("#"+id+"").val(PayOrder_key.SMS_COUNT);
        if(PayOrder_key.DEL_FROM_ID == "smsText" || PayOrder_key.DEL_FROM_ID == "v_sms_Text"){
            $("#"+id+"").html(PayOrder_key.SMS_COUNT);
        }else{
            $("#"+id+"").html(pwd);
        }
    },
    editPwdCode : function(id){
        var smsText = $("#"+id+"").val();
        if(smsText != null && smsText != "" && smsText != undefined){
            PayOrder_key.SMS_COUNT = smsText.substr(0,smsText.length-1);
        }else{
            PayOrder_key.SMS_COUNT = "";
        }
        var pwd = "";
        for(var i=0;i<PayOrder_key.SMS_COUNT.length;i++){
            pwd += "●";
        }
        $("#"+id+"").val(PayOrder_key.SMS_COUNT);
        if(PayOrder_key.DEL_FROM_ID == "smsText" || PayOrder_key.DEL_FROM_ID == "v_sms_Text"){
            $("#"+id+"").html(PayOrder_key.SMS_COUNT);
        }else{
            $("#"+id+"").html(pwd);
        }
    },

    //判断是否订购完成弹窗 li.shishun 2020-07-27
    judgeCompleteWindow : function(notify_id,timestamp,data,sign){
        var params = {
            PRODUCT_ID : $("#product_id").val(),
            USER_ID : $("#user_id").val()
        }
        Service.excute("JUDGE_COMPLETE_WINDOW",false,params,function(reply){
            if(reply.flag != "0"){
                PayOrder.orderSuccessFixMsg();
                return;
            }

            //是否弹窗标志 0 是 ； 1 否
            if(reply.WINDOW_FLAG!="0"){
                PayOrder.orderSuccessFixMsg();
                return;
            }

            //判断是否华为平台，是则弹窗（中兴机顶盒）
            var return_url = $("#return_url").val();
            if(return_url.indexOf('Category.jsp')== -1){
                PayOrder.orderSuccessFixMsg();
                return;
            }
            var book_flag= $("#book_type").val();;
            if(undefined != book_flag && null != book_flag && "3" == book_flag){
                PayOrder_window.showReportWindow("预约成功！","2");
            }else{
                PayOrder_window.showReportWindow("订购成功！","2");
            }
            setTimeout(function(){
                PayOrder_window.hideReportWindow();
                //华为机顶盒跳转弹窗
                var product_id = $("#product_id").val();
                var user_id = $("#user_id").val();
                var url = "/servlet/CompleteWindowServlet";
                window.location.href = url + "?ProductID=" + product_id +"&UserID=" + user_id+"&ReturnURL=" + return_url+"&notify_id=" + notify_id
                    +"&timestamp=" + timestamp+"&data=" + data+"&sign=" + sign;
            },3000);

        });
    },
    orderSuccessFixMsg : function(){
        var book_flag= $("#book_type").val();
        //提示用户订购成功
        if(undefined != book_flag && null != book_flag && "3" == book_flag){
            PayOrder_window.showReportWindow("预约成功！","2");
        }else{
            PayOrder_window.showReportWindow("订购成功！","2");
        }
        //订购成功暂停3秒
        setTimeout(function(){
            PayOrder_window.hideReportWindow();
            PayOrder.standardPost($("#return_url").val(), PayOrder_QR.payCenterParams);
        },3000);
    },
    //设置光标
    getFocusMethod : function(){
        $("#div_box").hide();
        $("#account_pay").addClass("focuse");
    },

    //订购量统计
    getDataCountMethod : function(){
        var id = setInterval(function(){
            var params = {
                product_id : $("#product_id").val()
            }
            Service.excuteNoLoading("DATA_COUNT_ORDER",false,params,function(reply){
                if(reply.flag == "0"){
                    if(reply.ORDER_COUNT == "0" && reply.ORDER_SUCCES_COUNT == "0" && reply.DELAY_COUNT == "0" && reply.DELAY_SUCCES_COUNT == "0"){
                        $("#datacount").hide();
                        clearInterval(id);
                    }
                    //订购量统计
                    var book_flag= $("#book_type").val();;
                    if(undefined != book_flag && null != book_flag && "3" == book_flag){
                        //预约量统计
                        if(reply.DELAY_COUNT != "0" || reply.DELAY_SUCCES_COUNT != "0"){
                            $("#datacount").show();
                            $("#order_count").html("当前产品预约量 <big>"+reply.DELAY_COUNT+"<span>次</span></big>");
                            $("#order_succes_count").html("当前预约支付量 <big>"+reply.DELAY_SUCCES_COUNT+"<span>次</span></big>");
                        }
                    }else{
                        if(reply.ORDER_COUNT != "0" || reply.ORDER_SUCCES_COUNT != "0"){
                            $("#datacount").show();
                            $("#order_count").html("当前产品订购量 <big>"+reply.ORDER_COUNT+"<span>次</span></big>");
                            $("#order_succes_count").html("当前支付量 <big>"+reply.ORDER_SUCCES_COUNT+"<span>次</span></big>");
                        }
                    }

                } else {
                    clearInterval(id);
                }
            });
        }, 1000);
    }
};
$(function(){
    PayOrder.init();
});
//银河机顶盒专用--返回按键触发此方法
function keyBackEventHandler(){
    var btn_id = $(".focuse").attr("id");
    if (PayOrder_key.keyCode == "0") {
        window.Android.backAndroid();
        return false;
    }
    if (PayOrder_key.keyCode == "1") {
        PayOrder_key.manyAction('8',btn_id);
        return false;
    }
    if (PayOrder_key.keyCode == "2") {
        PayOrder_key.bhAction('8',btn_id);
        return false;
    }
    if (PayOrder_key.keyCode == "3") {
        PayOrder_key.resetAction('8',btn_id);
        return false;
    }
    if (PayOrder_key.keyCode == "99") {
        PayOrder_key.errorAction('8',btn_id);
        return false;
    }
    return false;
}

